<?php

namespace app\admin\controller;

use think\Db;


class User extends Admincontroller
{
    public function index()
    {
        // 原生
        $sql = "SELECT * FROM user";
        $list = Db::query($sql);

        $sql = "SELECT * FROM user WHERE id=?";
        $list = Db::query($sql, [6]);

        // DB类
        $list = Db::table('user')->order(['id'=>'desc'])->select();

        // 助手函数
        $list = db('user')->select();

        dump($list);
    }

    public function insert()
    {
        // 原生
//        $result = Db::execute('INSERT INTO user (id,name) VALUES(null,"k1")');
//        $result = Db::execute('INSERT INTO user (id,name) VALUES(:id,:name)', ['id'=>null, 'name'=>'k2']);


        $data = [
            'name'=>'k4',
            'age'=>'88'
        ];
        // DB类
//        $result =  Db::table('user')->insert($data);
        $result =  Db::table('user')->insertGetId($data);

        // 助手函数
        dump($result);
    }


    public function delete()
    {
        // 原生

        // DB类
//        $result = Db::tabLe('user')->delete(40);
        $result = Db::table('user')->where('name','k1')->delete();
        // 助手函数
        dump($result);
    }

    public function update()
    {
        // 原生

        // DB类
        $result = Db::table('user')->where('id',1)->update(['age'=>19]);

        // 助手函数

        dump($result);

    }


}
